Object subclass: #InorderTraversal
	instanceVariableNames: 'tree stack'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'BinTree'!

!InorderTraversal methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:32'!
first
	"return the first object in the tree"
	| theTree |
	stack := Stack new initialize.
	theTree := tree.
	[ theTree notNil ] whileTrue: [ stack push: theTree. theTree := theTree leftKid. ].
	(stack isEmpty) ifTrue: [ ^nil ] ifFalse: [ ^stack top label ].! !

!InorderTraversal methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 16:31'!
next
	"return the next node of the tree"
	| theTree |
	theTree := stack pop rightKid.
	[ theTree notNil ] whileTrue: [ stack push: theTree. theTree := theTree leftKid. ].
	(stack isEmpty) ifTrue: [ ^nil ] ifFalse: [ ^stack top label ].! !

!InorderTraversal methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 15:50'!
setTree:theTree
	"set the tree used for this traversal"
	tree := theTree.! !

!InorderTraversal methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 15:50'!
tree
	"return the tree being traversed"
	^tree.! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

InorderTraversal class
	instanceVariableNames: ''!

!InorderTraversal class methodsFor: 'as yet unclassified' stamp: 'RGB 3/8/2011 15:49'!
new:theTree
	"create a new InorderTraversal with the specified tree"
	| theTraversal |
	theTraversal := super new initialize.
	theTraversal setTree: theTree.
	^theTraversal.! !
